<template>
  <a-spin :spinning="confirmLoading">
    <a-form-model ref="form" :model="models" :rules="validatorRules">
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName" required label="商品核心名称">
        <a-input placeholder="填写商品的核心词，可以两到三个，比如: 打底衫 毛衣" v-model="models.productName" />
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productAttribute" required label="商品属性">
        <a-input placeholder="比如: 2023款 秋季 纯棉长袖" v-model="models.productAttribute" />
      </a-form-model-item>
      <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platform" required label="电商平台">
        <div class="editIconMore">
          <j-search-select-tag
            placeholder="请添加卖点"
            v-model="models.platform"
            :dictOptions="searchOptions"
            mode="multiple"
            style="min-width: 200px;"
          >
          </j-search-select-tag>
          <div class="addIcon" @click="addShop" v-if="addIconShow">添加</div>
          <input type="text" class="shuInput" placeholder="请输入" v-model="shoppIngIcon" @change="search" v-else />
        </div>
      </a-form-model-item>
    </a-form-model>
  </a-spin>
</template>

<script>
export default {
  name: 'CommerceProducts',
  components: {
  },
  props: {
    model: {
      type: Object,
      default: {},
    },
  },

  data() {
    return {
      addIconShow: true,
      searchOptions: [
        {
          text: '抖音',
          value: '抖音',
        },
        {
          text: '淘宝',
          value: '淘宝',
        },
        {
          text: '京东',
          value: '京东',
        },
        {
          text: '天猫',
          value: '天猫',
        },
        {
          text: '唯品会',
          value: '唯品会',
        },
        {
          text: '拼多多',
          value: '拼多多',
        },
        {
          text: '其它',
          value: '其它',
        },
      ],
      shoppIngIcon: '',
      models: this.model,
      confirmLoading: false,
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 12 },
      },
      validatorRules: {
        productName : [{ required: true, message: '请输入商品核心名称' }],
        productAttribute : [{ required: true, message: '请输入商品属性' }],
        platform : [{ required: true, message: '请输入平台' }],
      },
     
    }
  },

  created() { },
  computed: {},
  updated(){
    
  },
  mounted() {
    this.$nextTick(function(){
      console.log('11111111111111111',this.models)
    })

  },
  methods: {
    // 添加标签
    addShop() {
      this.addIconShow = false
    },
    search(event) {
      let str = event.target.value
      this.shoppIngIcon = ''
      if(this.models.platform === undefined || this.models.platform === ''){
        this.models.platform = ''
        this.models.platform = str
      }else{
        this.models.platform +=  ',' + str
      }
      this.addIconShow = true
    },
    generatedBtnProp() {
      let obj = {
        productName:this.models.productName,
        productAttribute:this.models.productAttribute,
        platform:this.models.platform,
      }
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$emit('appApiAsk', 1,obj)
        } else {
          this.$emit('appApiAsk', 2,obj)
        }
      })
    },

  },
}
</script>

<style lang="less">

</style>